package 剑指Offer.easy;

public class 两个链表的第一个公共节点 {

    public class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
            next = null;
        }
    }

    public class Solution {
        public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
            ListNode ptrA = headA, ptrB = headB;
            while (ptrA != ptrB) {
                ptrA = ptrA.next != null ? ptrA.next : headB;
                ptrB = ptrB.next != null ? ptrB.next : headA;
            }
            return ptrA;
        }
    }
}
